package com.example.demo.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-10-31
 * Time: 13:19
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/say")
    public String say(){
        System.out.println("执行了say");
        //0作为被除数的算数异常
        int a = 10/0;
        return "hello say";
    }
    //先执行了前置通知了 然后在执行的say方法

    @RequestMapping("/login")
    public boolean login(HttpServletRequest request, String username, String password){
        boolean ret = false;
        if (StringUtils.hasLength(username) && StringUtils.hasLength(password)){
            if (username.equals("admin") && username.equals("admin")){
                HttpSession session = request.getSession();
                session.setAttribute("userinfo","userinfo");
                ret = true;
            }
        }
        return ret;
    }


    @RequestMapping("/index")
    public String index(){
        int num = 10 / 0;
        return "hello.index!";
    }
}
